<%@ page import="databean.Email"%>
<%@ page import="java.util.ArrayList" %>

<a href="user-logout.do">Log Out</a><br>

<div id="header">
<h1>Emails</h1>
</div>

<div id="user-view-emails">

<%
	ArrayList<Email> emails = (ArrayList<Email>) request.getAttribute("emails");
	
	for (int i=emails.size()-1; i>=0; i--) {
		
		Email email = emails.get(i);
		
		long conversationID = email.getConversationID();
		
%>

		Conversation ID: <%= email.getConversationID() %><br>
		Outlook ID: <%= email.getOutlookID() %><br>
		Email ID: <%= email.getEmailID() %><br>
		Timestamp: <%= email.getTimestamp() %><br>
		Sender: <%= email.getSender() %><br>
		Recipient: <%= email.getRecipient() %><br>
		Subject: <%= email.getSubject() %><br>
		Body: <%= email.getBody() %><br>
		Notes: <%= email.getNotes() %><br><br>

<%
		

		
		for (int j=i-1; j>=0; j--) {
			
			Email email2 = emails.get(j);
			
			if (conversationID == email2.getConversationID()) {
%>

				Outlook ID: <%= email2.getOutlookID() %><br>
				Email ID: <%= email2.getEmailID() %><br>
				Timestamp: <%= email2.getTimestamp() %><br>
				Sender: <%= email2.getSender() %><br>
				Recipient: <%= email2.getRecipient() %><br>
				Subject: <%= email2.getSubject() %><br>
				Body: <%= email2.getBody() %><br>
				Notes: <%= email2.getNotes() %><br><br>

<%

			}

		}

		for (int k=emails.size()-1; k>=0; k--) {
			
			Email email3 = emails.get(k);
			
			if (conversationID == email3.getConversationID()) {
				emails.remove(k);
			}
		}
		
		i = emails.size();
%>
		<hr>
<%
	}
%>

</div>